package cn.xxd.xxdwebsso.controller;

import cn.xxd.entity.LoginUser;
import cn.xxd.entity.ReturnT;
import cn.xxd.xxdssointerface.RegisterService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RegisterController {

    @Reference(version = "1.0.0")
    private RegisterService registerService;

    @Value("${HOMEURL}")
    private String HOMEURL;

    @Value("${SSOURL}")
    private String SSOURL;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String registerPage(Model model) {
        model.addAttribute("HOMEURL", HOMEURL);
        model.addAttribute("SSOURL", SSOURL);
        return "login";
    }

    @RequestMapping("/user/check/{param}/{type}")
    @ResponseBody
    public ReturnT checkData(@PathVariable String param, @PathVariable Integer type) {
        ReturnT result = registerService.checkData(param, type);
        return result;
    }


    @RequestMapping(value = "/user/register", method = RequestMethod.POST)
    @ResponseBody
    public ReturnT register(LoginUser user) {
        ReturnT result = registerService.register(user);
        return result;
    }

}
